package com.nbsaas.boot.article.rest.convert;

import com.nbsaas.boot.article.data.entity.Article;
import com.nbsaas.boot.article.api.domain.simple.ArticleSimple;

import com.nbsaas.boot.rest.api.Converter;

/**
 * -列表对象转换器
 */

public class ArticleSimpleConvert implements Converter<ArticleSimple, Article> {


    @Override
    public ArticleSimple convert(Article source) {
        ArticleSimple result = new ArticleSimple();

        result.setImages(source.getImages());
        result.setImg(source.getImg());
        result.setComments(source.getComments());
        if (source.getCatalog() != null) {
            result.setCatalog(source.getCatalog().getId());
        }
        if (source.getDocument() != null) {
            result.setDocument(source.getDocument().getId());
        }
        result.setTitle(source.getTitle());
        result.setAddDate(source.getAddDate());
        if (source.getCatalog() != null) {
            result.setCatalogName(source.getCatalog().getName());
        }
        result.setExtData(source.getExtData());
        result.setUps(source.getUps());
        if (source.getStoreState() != null) {
            result.setStoreStateName(String.valueOf(source.getStoreState()));
        }
        result.setStoreState(source.getStoreState());
        result.setId(source.getId());
        if (source.getUser() != null) {
            result.setUser(source.getUser().getId());
        }
        result.setIntroduction(source.getIntroduction());
        result.setViews(source.getViews());
        result.setLikes(source.getLikes());
        result.setLastDate(source.getLastDate());


        return result;
    }

}